<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>花间村 - 商品库存管理</title>
    <link rel="stylesheet" href="{{ asset('css/wechat_service_account.css') }}">
    <style>
        .container {
            padding: 15px;
        }

        .header {
            background: #fff;
            padding: 20px;
            border-radius: 12px;
            margin-bottom: 20px;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
            text-align: center;
        }

        .header h2 {
            margin: 0;
            color: #333;
            font-size: 20px;
        }

        .back-btn {
            margin-top: 15px;
            padding: 12px 20px;
            background: #1890ff;
            color: white;
            border: none;
            border-radius: 20px;
            font-size: 14px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
        }

        .back-btn:hover {
            background: #40a9ff;
        }

        .product-item {
            background: #fff;
            border-radius: 12px;
            padding: 15px;
            margin-bottom: 15px;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
        }

        .product-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 10px;
            border-bottom: 1px solid #f0f0f0;
        }

        .product-name {
            font-size: 16px;
            color: #333;
            font-weight: 500;
        }

        .product-stock {
            font-size: 16px;
            font-weight: 600;
        }

        .low-stock {
            color: #e53e3e;
        }

        .normal-stock {
            color: #38a169;
        }

        .product-details {
            padding: 10px 0;
        }

        .detail-row {
            display: flex;
            justify-content: space-between;
            padding: 5px 0;
            font-size: 14px;
            color: #666;
        }

        .product-footer {
            padding-top: 10px;
            text-align: right;
        }

        .edit-link {
            color: #1890ff;
            text-decoration: none;
            font-size: 14px;
        }

        .edit-link:hover {
            text-decoration: underline;
        }

        .pagination {
            text-align: center;
            margin-top: 20px;
            padding-bottom: 30px;
        }

        .pagination a {
            display: inline-block;
            padding: 8px 12px;
            margin: 0 5px;
            background: #fff;
            border: 1px solid #ddd;
            border-radius: 4px;
            text-decoration: none;
            color: #333;
        }

        .pagination a.active {
            background: #07C160;
            color: white;
            border-color: #07C160;
        }

        .no-products {
            background: #fff;
            padding: 30px;
            border-radius: 12px;
            text-align: center;
            color: #666;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="header">
            <h2>商品库存管理</h2>
            <a href="{{ route('wechat.service.account.admin') }}" class="back-btn">返回管理面板</a>
        </div>

        @if($products->count() > 0)
        @foreach($products as $product)
        <div class="product-item">
            <div class="product-header">
                <div class="product-name">{{ $product->name }}</div>
                <div class="product-stock {{ $product->stock < 10 ? 'low-stock' : 'normal-stock' }}">
                    库存: {{ $product->stock }}
                </div>
            </div>
            <div class="product-details">
                <div class="detail-row">
                    <span>价格:</span>
                    <span>¥{{ number_format($product->price, 2) }}</span>
                </div>
                <div class="detail-row">
                    <span>销量:</span>
                    <span>{{ $product->sales_count }}</span>
                </div>
                <div class="detail-row">
                    <span>状态:</span>
                    <span>{{ $product->status ? '销售中' : '已下架' }}</span>
                </div>
            </div>
            <div class="product-footer">
                <!-- 修改编辑商品链接，指向微信服务号专用的商品编辑页面 -->
                <a href="{{ route('wechat.service.account.product.edit', $product->id) }}" class="edit-link">编辑商品</a>
            </div>
        </div>
        @endforeach

        @else
        <div class="no-products">
            暂无商品数据
        </div>
        @endif

        <!-- 分页显示 -->
        @if($products->hasPages())
        <div class="pagination">
            {{ $products->links() }}
        </div>
        @endif
    </div>
</body>

</html>